package binTree;
//589. N 叉树的前序遍历
import java.util.ArrayList;
import java.util.List;
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
public class Num589_preorder {
    private List<Integer> res = new ArrayList<>();

    public List<Integer> preorder(Node root) {
        helper(root,res);
        return res;

    }
    public void helper(Node root, List<Integer> res) {
        if (root==null){
            return;
        }
        res.add(root.val);
        for (Node ch:root.children){
            helper(ch,res);
        }

    }

}
